<template>
  <div class="side">
    <div style="width:100%">
      <div class="register">
        <el-row>
          <el-button @click="createData" class="dakai" type="primary">提交</el-button>
        </el-row>
      </div>
      <el-form :model="CouponSet" label-position="right" label-width="181px" ref="dataForm">
        <el-form-item label="优惠码">
          <el-radio-group v-model="CouponSet.status">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import {addCouponSetData, getCouponSetData} from '@/api/system/couponset';
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        CouponSet: {
          status: '',
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getCouponSetData(getTenantId()).then(response => {
          this.CouponSet = response.data
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.CouponSet.tenantId = getTenantId();
            addCouponSetData(this.CouponSet).then(() => {
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .register {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
  }

  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }
</style>
